package com.hnx.admin.aurora.system.controller;

import com.hnx.admin.aurora.annotation.Log;
import com.hnx.admin.aurora.enums.BusinessType;
import com.hnx.admin.aurora.system.domain.dto.post.query.PostQuery;
import com.hnx.admin.aurora.system.domain.param.post.form.PostForm;
import com.hnx.admin.aurora.system.service.SysPostService;
import com.hnx.admin.aurora.utils.UUIDUtil;
import com.hnx.admin.aurora.web.json.ResultJson;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/*
创建人： 倔强的头发
创建时间：2025/7/2
功能描述:

*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/system/post")
public class SysPostController {
    private final SysPostService sysPostService;
    /**
     * 获取岗位列表
     */
    @PreAuthorize("@auth.hasPermi('system:post:list')")
    @GetMapping("/list")
    public ResultJson list(PostQuery post)
    {
        return sysPostService.selectPostList(post);
    }
    /**
     * 新增岗位
     */
    @PreAuthorize("@auth.hasPermi('system:post:add')")
    @Log(title = "岗位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultJson add(@Validated @RequestBody PostForm post)
    {
        post.setPostId(UUIDUtil.getUUID());
        return sysPostService.insertPost(post);
    }
    /**
     * 删除岗位
     */
    @PreAuthorize("@auth.hasPermi('system:post:remove')")
    @Log(title = "岗位管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{postIds}")
    public ResultJson remove(@PathVariable String[] postIds)
    {
        return sysPostService.deletePostByIds(postIds);
    }
    /**
     * 根据岗位编号获取详细信息
     */
    @PreAuthorize("@auth.hasPermi('system:post:query')")
    @GetMapping(value = "/{postId}")
    public ResultJson getInfo(@PathVariable String postId)
    {
        return sysPostService.selectPostById(postId);
    }
    /**
     * 修改岗位
     */
    @PreAuthorize("@auth.hasPermi('system:post:edit')")
    @Log(title = "岗位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultJson edit(@Validated @RequestBody PostForm post)
    {
        return sysPostService.updatePost(post);
    }
}
